var app = getApp();
Page({
  data: {
  	order:{},
  	id:null
  },
  onLoad(options) {
  	var $th=this;
  	if(options){
	  	if(options.id){
	  		$th.data.id=options.id
	  		console.log(options.id)
	  	}
  	}
  	app.globalAjax(
	  		'/api/order/detail',
	  		"get",
	  		{id:$th.data.id},
	  		function(e){
	  			if(e.code==0)
	      	{
	      		$th.setData({
					      order: e.order
					  })
	      	}else{
	      		wx.showToast({
				        title: e.msg,
				        icon: "none"
				      });
	      	}
	  	})
  },
  againorder:function(){//再来一单
  	var that=this,
  			$data=that.data
  	var total=$data.order.totalAmount
  	total=parseFloat(total).toFixed(2)
  	var orderdata={
			  orderGoodsList: $data.order.orderGoodsList,
			  total:total,//合计
			  remark: "",//备注
			  storeId: 0,//供应商ID
			  totalAmount: 0,//总金额
			}
  		wx.setStorage({
			   key: "orderlist",
			   data: orderdata //需要存储的数据
			})
	  	wx.redirectTo({
			  url: '/pages/cart/pay/pay'
			})
  },
  Qpay:function(e){//订单付款
  	var that=this
		  	app.globalAjax(
			  		'/api/unifiedOrder',
			  		"post",
			  		{
			  			orderNumber:that.data.order.orderNumber,
			  			totalAmount:0.1
			  		},
			  		function(e){
			  			if(e.code==0)
			      	{
			      		app.pays(e.data,function(ee){
			      			console.log("付款成功")
			      			that.onLoad()
			      		},function(){
			      			console.log("付款失败")
			      		})
			      	}else{
			      		wx.showToast({
						        title: e.msg,
						        icon: "none"
						      });
			      	}
			  })
  },
  Qclear:function(){//取消订单
  	var that=this;
  	
  	wx.showModal({
		  title: '取消',
		  content: '确定取消订单吗？',
        success(res) {
            if (res.confirm) {
            	
		  	app.globalAjax(
			  		'/api/order/cancel',
			  		"get",
			  		{
			  			id:that.data.id
			  		},
			  		function(e){
			  			if(e.code==0)
			      	{
			      		that.onLoad()
			      	}else{
			      		wx.showToast({
						        title: e.msg,
						        icon: "none"
						      });
			      	}
			  })
  
            }else if(res.cancel) {
          	}
       }
   })
  },
  Qconfirm:function(){//确认收货
  	var that=this;

  	wx.showModal({
		  title: '完成',
		  content: '确定已经收货吗？',
        success(res) {
            if (res.confirm) {
            	
		  	app.globalAjax(
			  		'/api/order/complete',
			  		"get",
			  		{
			  			id:that.data.id
			  		},
			  		function(e){
			  			if(e.code==0)
			      	{
			      		that.onLoad()
			      	}else{
			      		wx.showToast({
						        title: e.msg,
						        icon: "none"
						      });
			      	}
			  })
  
            }else if(res.cancel) {
          	}
       }
   })
  }
})